package com.controller;

import com.dto.excution.ListExcution;
import com.entity.AssociationInfo;
import com.enums.ListEnum;
import com.service.CollectionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("collection")
public class CollectionController {

    @Autowired
    private CollectionService service;

    @ApiOperation(value = "查是否收藏了此人")
    @PostMapping(value = "/findCollectionWhereId")
    @ResponseBody
    public ListExcution<Void> findCollectionWhereId(Integer stdUserId,Integer teaUserId){
        int collection = service.findCollectionWhereId(stdUserId,teaUserId);
        if(collection > 0){
            return new ListExcution<Void>(null, ListEnum.YSC);
        }else {
            return new ListExcution<Void>(null, ListEnum.WSC);
        }
    }

    @ApiOperation(value = "查是否申请了此人")
    @PostMapping(value = "/findApplyWhereId")
    @ResponseBody
    public ListExcution<Void> findApplyWhereId(Integer stdUserId,Integer teaUserId){
        int collection = service.findApplyWhereId(stdUserId,teaUserId);
        if(collection > 0){
            return new ListExcution<Void>(null, ListEnum.YSQ);
        }else {
            return new ListExcution<Void>(null, ListEnum.WSQ);
        }
    }

    @ApiOperation(value = "查看收藏数")
    @PostMapping(value = "/findCollCount")
    @ResponseBody
    public ListExcution findCollCount(Integer userId){
        int coll = service.findCollCount(userId);
        return new ListExcution(coll, ListEnum.SUCCESS);
    }

    @ApiOperation(value = "收藏和申请")
    @PostMapping(value = "/collect")
    @ResponseBody
    public ListExcution<Void> collect(Integer stdUserId, Integer teaUserId,String statusType){
        int coll = service.collect(stdUserId,teaUserId,statusType);
        if(coll>0){
            return new ListExcution<Void>(null, ListEnum.SUCCESS);
        }else {
            return new ListExcution<Void>(null, ListEnum.FAIL);
        }
    }

    @ApiOperation(value = "删除收藏1:SC(收藏),2:SQ(申请)")
    @PostMapping(value = "/deleteCollect")
    @ResponseBody
    public ListExcution<Void> DeleteCollect(Integer id){
        int collcount = service.DeleteCollect(id);
        if(collcount > 0){
            return new ListExcution<Void>(null, ListEnum.SUCCESS);
        }else {
            return new ListExcution<Void>(null, ListEnum.FAIL);
        }
    }

    @ApiOperation(value = "查询收藏列表")
    @PostMapping(value = "/findCollect")
    @ResponseBody
    public ListExcution<List<AssociationInfo>> findCollect(Integer stdUserId, Integer type,Integer limit){
        List<AssociationInfo> Association = service.findCollect(stdUserId,type,limit);
        return new ListExcution<List<AssociationInfo>>(Association, ListEnum.SUCCESS);
    }

    @ApiOperation(value = "查询我的申请列表")
    @PostMapping(value = "/findSQlist")
    @ResponseBody
    public ListExcution<List<AssociationInfo>> findSQlist(Integer teaUserId,Integer limit){
        List<AssociationInfo> Association = service.findSQlist(teaUserId,limit);
        return new ListExcution<List<AssociationInfo>>(Association, ListEnum.SUCCESS);
    }

}
